package com.pro.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;
import com.pro.dao.impl.BannerDaoImpl;
import com.pro.dao.impl.CompanyDaoImpl;
import com.pro.entity.BannerEntity;
import com.pro.entity.CompanyEntity;
import com.pro.util.BaseServlet;
import com.pro.util.DateUtil;
import com.pro.util.Result;
import com.pro.util.ResultToLayui;

/**
 * Servlet implementation class TestServlet
 * @param <Gson>
 */
public class CompanyAdminServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	BannerDaoImpl bDaoImpl = new BannerDaoImpl();
	CompanyDaoImpl cDaoImpl = new CompanyDaoImpl();
	
	public void company(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		
		  ArrayList<CompanyEntity> aList = cDaoImpl.companyAll();
		  PrintWriter out = response.getWriter(); 
		  out.print(ResultToLayui.toClient(0, "", aList.size(), aList));
		  out.flush(); 
		  out.close(); 
	}
	
	public void companyUpdate(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		
		  int id= Integer.parseInt(request.getParameter("companyId"));
		  String logo = request.getParameter("logo");
		  String companyIntr = request.getParameter("companyIntr");
		  String companyCulture = request.getParameter("companyCulture");
		  String companyTel = request.getParameter("companyTel");
		  String companyAddress = request.getParameter("companyAddress");
		  String companyPhone = request.getParameter("companyPhone");
		  String companyEmail = request.getParameter("companyEmail");
		  String url = request.getParameter("url");
		  String companyImg = request.getParameter("companyImg");
		  String x = request.getParameter("x");
		  String y = request.getParameter("y");
		  int result = cDaoImpl.companyUpdate(new CompanyEntity(id, DateUtil.DateToDate(new Date()), companyIntr, companyCulture, companyTel, companyAddress, companyPhone, companyEmail, companyImg, companyImg, logo, url, x, y));
		  
		  PrintWriter out = response.getWriter(); 
		  out.print(Result.toClient("修改", result>0?true:false));
		  out.flush(); 
		  out.close(); 
	}
	
}
